package com.bawei.module_service.http

import com.bawei.lib_common.base.BaseViewModel
import com.bawei.lib_common.base.state.Failed
import com.bawei.lib_common.base.state.Loading
import com.bawei.lib_common.base.state.RequestEvent
import com.bawei.lib_common.base.state.Success
import com.bawei.module_service.R
import com.bawei.module_service.model.MaintainModelItem
import com.bawei.module_service.model.PatrolModelItem
import com.bawei.module_service.model.PollingModel
import com.bawei.module_service.model.PollingModelItem


import com.bawei.module_service.model.ServiceItemModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import javax.inject.Inject
@HiltViewModel
class ServiceViewModel @Inject constructor(private val repository: ServiceRepository): BaseViewModel() {

    //
    val ServiceLists= mutableListOf<ServiceItemModel>()
    fun initServiceItemList(){
        ServiceLists.add(ServiceItemModel(R.mipmap.car_img,"车辆管理"))
        ServiceLists.add( ServiceItemModel(R.mipmap.img_2,"车位管理"))
        ServiceLists.add( ServiceItemModel(R.mipmap.img_3,"访客管理"))
        ServiceLists.add( ServiceItemModel(R.mipmap.img_4,"维修管理"))
        ServiceLists.add( ServiceItemModel(R.mipmap.img_5,"公告管理"))
        ServiceLists.add( ServiceItemModel(R.mipmap.img_6,"考勤管理"))
        ServiceLists.add( ServiceItemModel(R.mipmap.img_7,"即时通讯"))
        ServiceLists.add( ServiceItemModel(R.mipmap.img_8,"设备设置"))
        ServiceLists.add( ServiceItemModel(R.mipmap.img_9,"房源信息"))
        ServiceLists.add( ServiceItemModel(R.mipmap.img_10,"物业报修"))
        ServiceLists.add( ServiceItemModel(R.mipmap.img_11,"巡检管理"))
        ServiceLists.add( ServiceItemModel(R.mipmap.img_12,"月卡会员"))

    }
    val mMaintainList= mutableListOf<MaintainModelItem>()

    val mMaintainList_new= mutableListOf<MaintainModelItem>()

    val mPatrolList= mutableListOf<PatrolModelItem>()
    //巡检列表
    val mPollingList= mutableListOf<PollingModelItem>()


    private val _mMaintain= MutableStateFlow<RequestEvent>(Loading)
    val mMaintainState
        get() = _mMaintain.asStateFlow()
    private val _mPatrol=MutableStateFlow<RequestEvent>(Loading)
    val mPatrol
        get() = _mPatrol.asStateFlow()


    private val _mPolling=MutableStateFlow<RequestEvent>(Loading)
    //巡检列表
    val mPollingState
        get() = _mPolling.asStateFlow()
    //维修列表
    fun getMaintainList(){
        execute(
            action = repository.getMaintainList(),
            onStart = {
                _mMaintain.value = Loading
            },
            onError = {
                _mMaintain.value =Failed(it)
            },
            onFinish = {
                mMaintainList.clear()
                mMaintainList.addAll(it.data)
                _mMaintain.value = Success

            }
        )

    }

    fun getPatrolList(){
        execute(
            action = repository.getPatrolList(),
            onStart = {
                _mPatrol.value = Loading
            },
            onError = {
                _mPatrol.value =Failed(it)
            },
            onFinish = {
                mPatrolList.clear()
                mPatrolList.addAll(it.data)
                _mPatrol.value = Success

            }
        )
    }

    //巡检管理
    fun getPollingList(){
        execute(
            action = repository.getPollingList(),
            onStart = {
                _mPolling.value = Loading
            },
            onError = {
                _mPolling.value =Failed(it)
            },
            onFinish = {
                mPollingList.clear()
                mPollingList.addAll(it.data)
                _mPolling.value = Success

            }
        )
    }






}